<?php

namespace App\Http\Controllers\student;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Model\TheClass;
use App\Model\ClassStudent;

class IndexController extends Controller
{
    public function index()
    {

        $student = Auth::guard('student')->user();
        $classModel = new TheClass();
        $classStudentModel = new ClassStudent();
        $classStudent = $classStudentModel->where('student_id', $student->id)->get();
        $class_ids = $classStudent->pluck('class_id');
        $classes = $classModel->with('teacher')->whereIn('id', $class_ids)->get();

        return view('student.index', compact('classes'));
    }
}
